package com.wfm.threadpooltaskexecutor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;

@Slf4j
public class Main {

    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(PoolConfig.class); //1

        TaskTest taskTest = (TaskTest) context.getBean("taskTest");

        taskTest.execAsync();
        taskTest.getTaskExecutor().execute(taskTest::execSync);//这里也可以直接通过customExecutor名字拿到线程池
        taskTest.execSync();

        ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) context.getBean("customSchedule");
        CronTrigger cronTrigger = new CronTrigger("");
        scheduler.execute(taskTest::execSync);

        Thread.sleep(2000);
        context.close();
    }


}